package com.abaaba.project2.controller;


import com.abaaba.project2.bean.bo.*;
import com.abaaba.project2.bean.vo.*;
import com.abaaba.project2.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@RestController
@RequestMapping("/admin/coupon")
public class CouponController {

    @Autowired
    CouponService couponService;


    @RequestMapping("/list")
    public BaseRespVo list(CouponReqBo baseReqBo) {
        CouponListVo couponListVo = couponService.queryCoupon(baseReqBo);
        return BaseRespVo.ok(couponListVo);
    }

    /**
     * 添加优惠券
     * @param addCouponReqBo
     * @return
     * @throws ParseException
     */
    @RequestMapping("/create")
    public BaseRespVo create(@RequestBody AddCouponReqBo addCouponReqBo) throws ParseException {
        AddCouponVo addCouponVo = couponService.createCoupon(addCouponReqBo);
        return BaseRespVo.ok(addCouponVo);
    }

    @RequestMapping("/update")
    public BaseRespVo update(@RequestBody UpdateCouponBo updateCouponBo) throws ParseException {

        UpdateCouponVo updateCouponVo = couponService.updateCoupon(updateCouponBo);

        return BaseRespVo.ok(updateCouponVo);
    }

    @RequestMapping("/delete")
    public BaseRespVo delete(@RequestBody UpdateCouponBo updateCouponBo){
        couponService.deleteCoupon(updateCouponBo);
        return BaseRespVo.ok();
    }

    /**
     * 显示商品详情
     * @param id
     * @return
     */
    @RequestMapping("/read")
    public BaseRespVo read(Integer id){
      CouponDetailVo couponDetailVo = couponService.queryCouponById(id);
        return BaseRespVo.ok(couponDetailVo);
    }

    @RequestMapping("/listuser")
    public BaseRespVo listuser(CouponAndUserReqBo couponAndUserReqBo){
    CouponAndUserVo couponAndUserVo = couponService.queryCouponAndUser(couponAndUserReqBo);
         return BaseRespVo.ok(couponAndUserVo);
    }
}
